import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)


//捕获router异常
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
     return routerPush.call(this, location).catch(error=> error)
}

const Home =() => import('views/home/Home.vue');
const Cart =() => import('views/cart/Cart.vue');
const Category =()=> import('views/category/Category.vue');
const Profile =()=>import('views/profile/Profile.vue');
const Detail =()=>import('views/detail/Detail.vue');


const routes = [
  {
    path:'/',
    redirect:'/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/cart',
    name: 'Cart',
    component: Cart
  },
  {
    path: '/category',
    name: 'Category',
    component: Category
  },
  {
    path: '/profile',
    name: 'Profile',
    component: Profile
  },
  {
    path: '/detail',
    name: 'Detail',
    component: Detail
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
